package easystudy.member.myboard;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import easystudy.dao.BoardDao;
import easystudy.dao.MemberDao;
import easystudy.dto.Board;

@Controller
public class DetailController {

	private BoardDao boardDao;
	
	private MemberDao memberDao;
	
	public void setBoardDao(BoardDao boardDao){
		this.boardDao = boardDao;
	}
	
	public void setMemberDao(MemberDao memberDao){
		this.memberDao = memberDao;
	}
	
	@RequestMapping(value="me_detail.me", method=RequestMethod.GET)
	public ModelAndView doSendDetail(@RequestParam("board_num")int board_num, 
			@RequestParam("member_num")int member_num, HttpServletRequest req){
		
		boardDao.addHitcount(board_num);
		
		Board boardMain = boardDao.getBoardDetail(board_num);
		boardMain.setNickname(memberDao.getMemberDetail(member_num).getNickname());
		List<Board> replyList = boardDao.getReply(board_num);
		
		for(Board board : replyList){
			board.setNickname(memberDao.getMemberDetail(board.getMember_num()).getNickname());
		}
		
		ModelAndView mav = new ModelAndView();
		mav.setViewName("me_detail");
		mav.addObject("main",boardMain);
		mav.addObject("replyList",replyList);
		return mav;
	}
	
}
